<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 *
 * 学员管理
 */
class Chuqin extends MY_Controller {
public $left_menu_min;

  function __construct(){
    parent::__construct();

    // $this->left_menu_min = array("menu" => "教务管理", "curr" => '/chuqin/today_class', "list" => array("作业管理" => "/classes/home_work_list", "面授课" => "/course_banke", "班级管理" => "/classes", "学员管理" => "/student", "出勤管理" => "/chuqin/today_class", "老师管理" => "/teacher", "课程分类" => "/offline_course/cate", "课程科目" => "/offline_course", "教室管理" => "/school_room", "校区管理" => "/school_campus"));
    //   $this->smarty->assign("left_menu_min", $this->left_menu_min);
    //   $this->smarty->assign("menu", 'classes');
      $parent_id = 6;
      //获取school二级菜单
      $this->load->model('School_manage_menu_model');
      $menu_list = $this->School_manage_menu_model->get_menu_list($this->is_manage,$parent_id);
      // print_r($menu_list);exit;
      $this->smarty->assign("menu_list", $menu_list);

      $this->left_menu_min = array("menu" => "教务管理", "curr" => '/chuqin/today_class', "list" => $menu_list);
      $this->smarty->assign("left_menu_min", $this->left_menu_min);

      $this->smarty->assign("menu", 'classes');

  }

  /**
   * 今日上课
   * @return [type] [description]
   */
  public function today_class($date='')
  {
  	$today = date('Y-m-d');
  	// print_r($tomorrow);exit;
  	 $this->smarty->assign("tomorrow", date('Y-m-d',strtotime("$today +1 day")));
  	 $this->smarty->assign("canshu", $date);

  	//获取今日上课的班级
  	$this->load->model('Class_plan_model');
  	$pant_list = $this->Class_plan_model->get_today_class($date,$this->user_data['school_id']);
  	$this->smarty->assign("pant_list", $pant_list);
  	// print_r($pant);exit;

  	//select * from edu_o2o_class_plan where class_date = "2017-03-12"
  	$this->smarty->display("chuqin/today_class.html");
  }

  /**
   * 今日签到
   * @param  string $value [description]
   * @return [type]        [description]
   */
  public function today_signin($time=0, $limit = 0)
  {
    $post_data = $this->input->post();
    if($post_data){
      $time = !empty($post_data['time']) ? strtotime($post_data['time']) : 0;
    }
    //获取今日签到
    $this->load->model('Student_signin_model');
    $conditions['time'] = $time;
    $conditions['school_id'] = $this->user_data['school_id'];
    $signin_list = $this->Student_signin_model->get_signin_list($limit, $this->offset, $conditions);
    //分页
    $this->load->library('pagination');
    $page_config['base_url'] = '/chuqin/today_signin/'.$time;
    $page_config['total_rows'] = $signin_list['count'];
    $page_config['per_page'] = $this->offset;
    $page_config['uri_segment'] = 4;
    $this->pagination->initialize($page_config);
    $pagination = $this->pagination->create_links();
    $this->smarty->assign("pagination", $pagination);
    $this->smarty->assign("signin_list", $signin_list['result']);
    $this->smarty->display("chuqin/today_signin.html");
  }

  /**
   * 请假list
   * @param  string $student [description]
   * @return [type]          [description]
   */
  public function leave_list($student=0, $limit = 0)
  {
    //获取请假list
    $post_data = $this->input->post();
    if($post_data){
      $student = !empty($post_data['student']) ? $post_data['student'] : 0;
    }
    $this->load->model('Student_leave_model');
    $conditions['student'] = $student;
    $leave_list = $this->Student_leave_model->get_leave_list($this->user_data['school_id'], $limit, $this->offset, $conditions);
    $this->load->library('pagination');
    $page_config['base_url'] = '/chuqin/leave_list/'.$student;
    $page_config['total_rows'] = $leave_list['count'];
    $page_config['per_page'] = $this->offset;
    $page_config['uri_segment'] = 4;
    $this->pagination->initialize($page_config);
    $pagination = $this->pagination->create_links();
    $this->smarty->assign("pagination", $pagination);

    $this->smarty->assign("leave_list", $leave_list['result']);
     $this->smarty->assign("conditions", $conditions);
    $this->smarty->display("chuqin/leave_list.html");
  }

  /**
   * 添加请假记录
   * @param  string $value [description]
   * @return [type]        [description]
   */
  public function leave_add($value='')
  {
    $post_data = $this->input->post();
    if($post_data){
         $this->load->model('Student_leave_model');
         $this->Student_leave_model->add_leave($this->user_data['school_id'],$post_data);
         header("Location:/chuqin/leave_list");exit;
    }

    //获取学员list
    $this->load->model('School_student_model');
    $student_list = $this->School_student_model->get_student_simple_by_school($this->user_data['school_id']);
    $this->smarty->assign("student_list", $student_list);


    //获取班级list
    $this->load->model('Classo2o_model');
    $class_list = $this->Classo2o_model->get_class_simple_by_school($this->user_data['school_id']);
    $this->smarty->assign("class_list", $class_list);


    $this->smarty->display("chuqin/leave_add.html");
  }

  function delete_leave($ids = 0){
      if($_POST){
        $ids = $this->input->post('ids');
      }else{
        $ids = (array) $ids;
      }
      delete_data($ids, "o2o_student_leave");
      if($this->db->affected_rows() > 0){
        show_message($_SERVER['HTTP_REFERER'], "删除成功");
      }else{
        show_message($_SERVER['HTTP_REFERER'], "删除失败，请重试！");
      }
  }

  function delete_change($ids = 0){
      if($_POST){
        $ids = $this->input->post('ids');
      }else{
        $ids = (array) $ids;
      }
      delete_data($ids, "o2o_student_change");
      if($this->db->affected_rows() > 0){
        show_message($_SERVER['HTTP_REFERER'], "删除成功");
      }else{
        show_message($_SERVER['HTTP_REFERER'], "删除失败，请重试！");
      }
  }

  /**
   * 异动管理
   * @param  string $value [description]
   * @return [type]        [description]
   */
  public function change_list($student=0, $limit = 0)
  {
    $post_data = $this->input->post();
    if($post_data){
      $student = !empty($post_data['student']) ? $post_data['student'] : 0;
    }
    $this->load->model('Student_change_model');
    $conditions['student'] = $student;
    $change_list = $this->Student_change_model->get_change_list($this->user_data['school_id'], $limit, $this->offset, $conditions);

    $this->load->library('pagination');
    $page_config['base_url'] = '/chuqin/change_list/'.$student;
    $page_config['total_rows'] = $change_list['count'];
    $page_config['per_page'] = $this->offset;
    $page_config['uri_segment'] = 4;
    $this->pagination->initialize($page_config);
    $pagination = $this->pagination->create_links();
    $this->smarty->assign("pagination", $pagination);
    $this->smarty->assign("conditions", $conditions);
    $this->smarty->assign("change_list", $change_list['result']);
    $this->smarty->display("chuqin/change_list.html");
  }


  /**
   * 添加异动记录
   * @param  string $value [description]
   * @return [type]        [description]
   */
  public function change_add($value='')
  {
    //获取校区
    $this->load->model('Schoolo2o_model');
    $campus_list = $this->Schoolo2o_model->get_school_campus($this->user_data['school_id']);
    $this->smarty->assign("campus_list", $campus_list);

    $post_data = $this->input->post();
    if($post_data){
         $this->load->model('Student_change_model');
         $this->Student_change_model->add_change($this->user_data['school_id'],$post_data);
         header("Location:/chuqin/change_list");exit;
    }

    //获取学员list
    // $this->load->model('School_student_model');
    // $student_list = $this->School_student_model->get_student_simple_by_school($this->user_data['school_id']);
    // $this->smarty->assign("student_list", $student_list);


    //获取班级list
    // $this->load->model('Classo2o_model');
    // $class_list = $this->Classo2o_model->get_class_simple_by_school($this->user_data['school_id']);
    // $this->smarty->assign("class_list", $class_list);


    $this->smarty->display("chuqin/change_add.html");
  }

}
